package org.blackjuly.sign.service;

import org.blackjuly.sign.data.DataBean;
import org.blackjuly.sign.data.DataTrimmer;
import org.blackjuly.sign.entity.User;

public class UserService extends BaseService {
	/**
	 * 根据用户名查找用户信息
	 */
	public User findUserByStudent(String student) throws Exception {
		DataBean<User> dataBean = new DataBean<>(conn, "user", "student");
		dataBean.setEntityClass(User.class);
		return dataBean.doSelect(student);
	}
	/**
	 * 检查用户名和密码是否匹配
	 */
	public boolean checkPassword(User user) {
		boolean flag = false;
		try {
			DataTrimmer dt = new DataTrimmer(conn);
			String sql = "select * from user where student = ? and pwd = ?";
			flag = dt.hasMoreData(sql, user.getStudent(), user.getPwd());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
	/**
	 * 检查是否有该学生
	 */
	public boolean checkHas(User user){
		boolean flag = false;
		try {
			String sql = "select * from user where student = ?";
			DataTrimmer dt = new DataTrimmer(conn);
			flag = dt.hasMoreData(sql, user.getStudent());
		} catch (Exception e){
			e.printStackTrace();
		}
		return flag;
	}
	
	/**
	 * 检查账号是否已经签到过
	 */
	public boolean checkRegiste(User user) {
		boolean flag = false;
		try {
			String sql = "select * from user where student = ? and parent != '' and pwd != ''";
			DataTrimmer dt = new DataTrimmer(conn);
			flag = dt.hasMoreData(sql, user.getStudent());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
	
	/**
	 * 用户注册  这个暂时没用
	 */
	public void registe(User user) throws Exception {
		DataBean<User> dataBean = new DataBean<>(conn, "user", "student");
		dataBean.doSave(user);
	}
	/**
	 * 用户签到
	 */
	public void sign(User user) throws Exception {
		DataBean<User> dataBean = new DataBean<>(conn, "user", "student");
		dataBean.doUpdate(user);
	}
}